package com.tarena.lbs.business.dao.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.tarena.lbs.business.dao.mapper.ChainMapper;
import com.tarena.lbs.business.dao.repository.ChainRepository;
import com.tarena.lbs.business.pojo.param.ChainQuery;
import com.tarena.lbs.business.pojo.po.ChainPO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Slf4j
@Repository
public class ChainRepositoryImpl implements ChainRepository {
    @Autowired
    private ChainMapper chainMapper;

    @Override
    public PageInfo<ChainPO> pageList(ChainQuery query) {
        QueryWrapper<ChainPO> wrapper = new QueryWrapper<>();
        List<Integer> storeId = query.getStoreId();
        if (storeId != null && storeId.size() > 0) {
            wrapper.in("store_id", storeId);
        }
        List<ChainPO> list = chainMapper.selectList(wrapper);
        log.info("查询结果：{}", list);
        return new PageInfo<>(list);
    }

    @Override
    public ChainPO findById(Integer id) {
        return chainMapper.selectById(id);
    }

    @Override
    public void update(ChainPO po) {
        chainMapper.updateById(po);
    }

    @Override
    public void save(ChainPO chainPO) {
        chainMapper.insert(chainPO);
    }

    @Override
    public void deleteById(Integer id) {
        log.info("删除店铺，入参:{}",id);
        QueryWrapper<ChainPO> wrapper = new QueryWrapper<>();
        wrapper.eq("store_id",id);
        chainMapper.delete(wrapper);
        log.info("删除店铺，出参:{}",wrapper);
    }
}
